define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'ykjp/inventory/procheck/index' + location.search,
                    add_url: 'ykjp/inventory/procheck/add',
                    edit_url: 'ykjp/inventory/procheck/edit',
                    del_url: 'ykjp/inventory/procheck/del',
                    multi_url: 'ykjp/inventory/procheck/multi',
                    table: 'check',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: true, //设置自定义表单
                searchFormTemplate: 'customformtpl',
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        // {field: 'firmid', title: __('Firmid')},
                        {field: 'name', title: __('Name')},
                        {field: 'specification', title: __('Specification')},
                        {field: 'prop', title: __('Prop')},
                        {field: 'unit', title: __('Unit')},
                        {field: 'w_name', title: __('W_name')},
                        {field: 'p_name', title: __('P_name')},
                        {field: 'surface_num', title: __('Surface_num')},
                        {field: 'number', title: __('Number')},
                        {field: 'real_num', title: __('Real_num')},
                        {field: 'type', title: __('Type'), searchList: {"盘盈入库": __('盘盈入库'), "盘亏出库": __('盘亏出库')}, formatter: Table.api.formatter.normal},
                        {field: 'updatetime', title: __('Updatetime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
                                // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
            Form.api.bindevent($("form[role=form]"), function (data, ret) {
                // window.top.location.href = 'statement?ref=addtabs';
            });
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});